package com.wimcorp.magic.abilities;

import javax.persistence.Entity;
import javax.persistence.Table;

import com.wimcorp.magic.abilities.trigger.AbilityTrigger;
import com.wimcorp.magic.board.CardType;
import com.wimcorp.magic.cards.Creature;
import com.wimcorp.magic.cards.Planeswalker;
import com.wimcorp.magic.cards.PlayingCard;
import com.wimcorp.magic.input.Target;

/**
 * example {target: 'ANY', types:[
 * 'CREATURE'],locations:['BATTLEFIELD'],behaviors:['FLYING'],amount:'2'}
 * 
 * target options : ANY,SELF,OPPONENT,THIS
 * 
 * types options : CREATURE,PLAYER,PLANESWALKER
 * 
 * location options : BATTLEFIELD
 * 
 * behaviors options :
 */
@Entity
@Table(name = "damagetarget", schema = "abilities")
public class DamageTarget extends Ability {

	private int amount;

	protected DamageTarget() {
	}

	public DamageTarget(AbilityTrigger trigger) {
		super(trigger);
	}
	
	public DamageTarget(DamageTarget ability){
		super(ability);
		this.amount = ability.getAmount();
	}

	@Override
	protected void executeAbility() {
		if (getInput() > 0) {
			PlayingCard card = getAbilityTarget();
			if (card != null) {
				if (card instanceof Creature) {
					((Creature) card).subtractLife(amount);
				} else if (card instanceof Creature) {
					((Planeswalker) card).subtractLoyality(amount);
				}
			}
		} else {
			if (getInput() == -100) {
				getPlayer().subtractLife(amount);
			} else {
				getPlayer().getOpponent().subtractLife(amount);
			}

		}

	}

	@Override
	public Ability clone() {
		return new DamageTarget(this);
	}
	
	@Override
	public boolean isInputRequired(){
		if (Target.THIS.equals(getTarget())) {
			return false;
		}
		return true;
	}

	public int getAmount() {
		return amount;
	}

	public void setAmount(int amount) {
		this.amount = amount;
	}
	
	

	
	
}
